package org.example.osproject01.Object;

import javafx.scene.control.TableColumn;

import java.util.UUID;

public class Job {
    UUID uuid;          //为每一个作业分配唯一一个UUID，随机生成，不会重复
    String name;        //作业的名字，由用户命名
    int submitTime;     //提交时间
    int runTime;        //运行时间
    int finishTime;     //完成时间
    int cyclingTime;    //周转时间
    Double weightedTime;//平均周转时间
    String runStatus;   //运行状态：主要有“输入中”，“就绪状态”，“运行状态”，“已完成”等状态。
    String spaceStatus; //空间状态：主要有“未分配”，“已分配内存”，“内存不足”等状态。
    int needSpace;      //所需的内存大小
    String atWhere;     //位于哪个内存块中
    int needTape;       //需要多少个磁带
    int priority;       //作业的优先级

    public Job(String name, String runTime, String needSpace, String needTape, String priority, String submitTime) {
        this.uuid = UUID.randomUUID();
        this.name = name;
        this.submitTime = Integer.parseInt(submitTime);
        this.runTime = Integer.parseInt(runTime);
        this.needSpace = Integer.parseInt(needSpace);
        this.needTape = Integer.parseInt(needTape);
        this.priority = Integer.parseInt(priority);
        this.weightedTime = 0.0;
        this.runStatus = "inputting";
        this.spaceStatus = "未分配";
        this.atWhere = "未分配";
    }

    public Item toItem() {
        return new Item(uuid,name,submitTime,runTime,cyclingTime,weightedTime,finishTime,runStatus,spaceStatus,needSpace,atWhere,needTape,priority);
    }

    @Override
    public String toString() {
        return "Job{" +
                "uuid=" + uuid +
                ", name='" + name + '\'' +
                ", submitTime=" + submitTime +
                ", runTime=" + runTime +
                ", finishTime=" + finishTime +
                ", cyclingTime=" + cyclingTime +
                ", weightedTime=" + weightedTime +
                ", runStatus='" + runStatus + '\'' +
                ", spaceStatus='" + spaceStatus + '\'' +
                ", needSpace=" + needSpace +
                ", atWhere='" + atWhere + '\'' +
                ", needTape=" + needTape +
                ", priority=" + priority +
                '}';
    }

    public String getId() {
        String sid = uuid.toString();
        return sid.substring(0,8);
    }
}
